﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RainyPWS.Common;
using RainyPWS.Model;
using RainyPWS.Business;

namespace RainyPWS.Web.Admin
{
    public partial class RecordTypeProcess : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = MRequest.GetInt("id", 0);
            if (!IsPostBack)
            {
                InitData(id);
            }
        }

        private void InitData(int id)
        {
            MRecordType obj = BRecordType.Instance.GetRecordTypeModelById(id);
            if (obj != null)
            {
                txtName.Text = obj.Name;
                txtRemark.Text = obj.Remark;
                hdnId.Value = obj.ID.ToString();
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            MRecordType obj = new MRecordType();
            obj.ID = Utils.StrToInt(hdnId.Value, 0);
            obj.Name = txtName.Text.Trim();
            obj.Remark = txtRemark.Text.Trim();
            int result;
            if (obj.ID != 0)
            {
                result = BRecordType.Instance.UpdateData(obj);
            }
            else
            {
                result = BRecordType.Instance.InsertData(obj);
            }
            if (result > 0)
            {
                Utils.ModalDialogClose(Page, "ok");
            }
        }
    }
}